package com.wdb.modules.security.security;

import com.wdb.modules.security.config.bean.SecurityProperties;
import com.wdb.modules.security.service.OnlineUserService;
import com.wdb.modules.security.service.UserCacheManager;
import lombok.RequiredArgsConstructor;
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.DefaultSecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

/**
 * @author: wendaobai@qq.com
 * @date: 2024/1/10 0010 16:11
 */
@RequiredArgsConstructor
public class TokenConfigurer
    extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {
  private final TokenProvider tokenProvider;
  private final SecurityProperties properties;
  private final OnlineUserService onlineUserService;
  private final UserCacheManager userCacheManager;

  @Override
  public void configure(HttpSecurity http) {
    TokenFilter customFilter =
        new TokenFilter(tokenProvider, properties, onlineUserService, userCacheManager);
    http.addFilterBefore(customFilter, UsernamePasswordAuthenticationFilter.class);
  }
}
